package cn.chencaiju.blog.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSON;

import cn.chencaiju.blog.domain.AjaxResponse;
import cn.chencaiju.blog.domain.Post;
import cn.chencaiju.blog.service.PostService;


@WebServlet(urlPatterns="/post/page")
public class PostServlet extends HttpServlet{
	private PostService service;
	
	@Override
	public void init() throws ServletException {
		super.init();
		service=new PostService();
		
	}
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		System.out.println("com here");
		AjaxResponse<Post> response = service.page();
		if(response!=null) {
			
			String jsonString = JSON.toJSONString(response);
			resp.setContentType("application/json;charset=utf-8");
			resp.getWriter().write(jsonString);
		}		
	}
}
